package com.mashibing.servicepassageruser.controller;

import com.mashibing.servicepassageruser.dto.PassengerUser;
import com.mashibing.servicepassageruser.service.UserService;
import org.mashibing.dto.ResponseResult;
import org.mashibing.request.VerificationCodeDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author:
 * @create: 2024/3/25 17:25
 * @description: 用户
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据手机号插入用户
     */
    @PostMapping("/user")
    public ResponseResult<String> loginOrRegister(@RequestBody VerificationCodeDTO verificationCodeDTO) {
        String passengerPhone = verificationCodeDTO.getPassengerPhone();

        return userService.loginOrRegister(passengerPhone);
    }

    /**
     * 根据手机号查询用户信息
     */
    @GetMapping("/user/{passengerPhone}")
    public ResponseResult<PassengerUser> getUser(@PathVariable String passengerPhone) {
        return userService.getUser(passengerPhone);
    }
}
